package com.hwj.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hwj.entity.Role;
import com.hwj.mapper.RoleMapper;
import com.hwj.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;
    @Override
    public Role selectByPrimaryKey(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> select() {
        return roleMapper.select();
    }

    @Override
    public PageInfo<Role> page(Role role, Integer pageSize, Integer pageNum) {
        if(role==null){
            role=new Role();
        }
        String roleName= role.getRoleName();
        String roleDescribe = role.getRoleDescribe();
        if(roleName!=null){
            roleName="%"+roleName+"%";
            role.setRoleName(roleName);
        }
        if(roleDescribe!=null){
            roleDescribe="%"+roleDescribe+"%";
            role.setRoleDescribe(roleDescribe);
        }
        if(pageNum!=null&&pageNum<=0){
            pageNum=1;
        }
        if(pageSize!=null&&pageSize<=0){
            pageSize=3;
        }
        if(pageNum!=null&&pageSize!=null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<Role> list=roleMapper.page(role);

        return new PageInfo<>(list);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Role record) {
        return roleMapper.insert(record);
    }

    @Override
    public int insertSelective(Role record) {
        return roleMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(Role record) {
        return roleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Role record) {
        return roleMapper.updateByPrimaryKeySelective(record);
    }
}
